<!DOCTYPE  HTML>
<html>
	<head>
		
	<script type="text/javascript" src="../resources/script.js"></script>
		<meta charset="utf-8">
  		<meta name="viewport" content="width=device-width, initial-scale=1">
  		<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
		  <script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
    	  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
		 
  		 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  		 <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
		
  		 <script>
				$(document).ready(function(){
  					$("#btnaddNewSession").click(function(){
    					$("#divSes").hide();
  					});
  					
				});
				$(document).ready(function(){
  					$("#btnaddSes").click(function(){
    					$("#divSes").show();
  						});
					});
				$(function(){
					$(".datepicker").datepicker({format: 'yyyy-mm-dd'});
				});

</script>
	<script type="text/javascript" src="../resources/bootstrap-datepicker.js"></script>
	<link rel="stylesheet" href="../resources/datepicker.css"></link >
	<link rel="stylesheet" href="../resources/style.css" />
	</head>
	<body>
		<?php
			foreach (glob("../model/*.php") as $filename)
                	{
                        	include_once $filename;
                	}

                	foreach (glob("../dao/*.php") as $filename)
                	{
                        	include_once $filename;
                	}

			/*array , TrainningSession -> boolean
			purpose. produces true if the given Session is found in the given array of Sessions, false other wise*/
			function found($sessn_list , $sessn)
			{
				$flag = false;

				foreach($sessn_list as $sessn_in_list)
				{
					if(($sessn_in_list->getSessionName() == $sessn->getSessionName()) && 
					(date('Y-m-d',$sessn_in_list) == date('Y-m-d', $sessn)))
					{
						$flag = true;
						break;
					}
				}
			}

			if($_SERVER['REQUEST_METHOD'] == 'POST')
			{
				$sess_name	= $_POST['tsesnm'];
				$trainer	= $_POST['trainer'];
				$on_date	= $_POST['tsdate'];
				$start_time	= $_POST['tstime'];
				$sts		= $_POST['sess_status'];
				$tech_name	= $_POST['sess_tech'];
				$desc		= $_POST['tsesnm'];
				$techdao	= new TechnologyDAOImpl();
				$sessdao	= new SessionDAOImpl();

				$tech_id	= $techdao->getIdFromName($tech_name); //!!! to add desc
				$sessn		= new TrainingSession($sess_name, $trainer, date("$on_date $start_time"), $sts, 
							null, null, $tech_id);

				$sessn_list	= $sessdao->listSessions()->getArrayList();
				if(isset($sessn_list))
				{
					if(!found($sessn_list, $sessn))
					{
						$sessdao->saveOrUpdate($sessn);
						//echo "!!!sessn added successfully";
					}
					else
					{
						echo "!!!sessn already exists";
					}
				}
				else
				{
					$sessdao->saveOrUpdate($sessn);
					echo "!!!sessn added successfully";
				}
			 }
		?>
		<div id="ahmainpnl" >
			
			<img id="ahlogo" src="../resources/logo.png"></img>
			<div id="ahheaderpnl">
				<p id="hSess">Training Sessions</p>
				<button id="btnaddNewSession" type="button"  class="btn btn-primary" data-toggle="collapse" data-target="#addnewSes" >Add Session</button>
  
			</div>
			<div id="ahmenupnl">
				 <a href="home_admin.php" id="ahbtnhome" class="btn btn-success">Home</a>
				<!--button type="button" id="ahbtnhome" class="btn btn-success" onclick="window.open('home_admin.html')">Home</button-->
				<hr/>
				<a href="addUser.php" id="ahbtnhome" class="btn btn-info">Users</a>
				<!--button type="button" id="ahbtnuser" class="btn btn-info" onclick="window.open('addUser.html')">Users</button-->
				<a href="addTechnology.php" id="ahbtnhome" class="btn btn-info">Technologies</a>
				<!--button type="button" id="ahbtntech" class="btn btn-info" onclick="window.open('addTechnology.html')">Technologies</button-->
				<a href="../login.html" style="margin-left: 0px;" >Logout</a>
			</div>
			<div id="ahcontentpnl" class="col-lg-6">
				
				
			<div class="container">
			<div id="addnewSes" class="collapse container">
			
			<form rotbladdsesle="form" name="addsessform" action='' method='POST'>
  					<table class="tbladd">
  						
  						<tr>
  							<td> <input type="text" class="form-control" id="tsesnm" name="tsesnm" placeholder="Session Title" required></td>
  							<td> <input type="text" class="form-control" id="trainer" name="trainer" placeholder="Trainer Name" required></td>
  							
  						</tr>
  						
  						<tr>
  							<td>
  									<select class="form-control" id="sess_tech" name="sess_tech" placeholder="Technology">
									<?php
										 $techdao   = new TechnologyDAOImpl();
										 $tech_list = $techdao->listTechnology()->getArrayList();
										if($tech_list != null)
										{
											foreach($tech_list as $tech)
											{
									?>
        								<option><?php print $tech->getTechName(); ?></option>
        										<?php
											}
										}
										else
										{?>
									<option>--No Technology--</option>
										<?php
										}
										?>
      								</select>
  							</td>
  							<td>
  									<select class="form-control" id="sess_status" name="sess_status" placeholder="Status">
        								<option>Available</option>
        								<option>NotAvailable</option>
      								</select>
  								
  							</td>
  							
  						</tr>
  						<tr>
  							<td>
  								<input type="text" class="datepicker" id="tsdate" name="tsdate" placeholder="Date"  style="width: 60%;" >
  							</td>
  							<td>
  								<input type="time" class="form-control" id="tstime" name="tstime" placeholder="Start Time" style="width: 60%;" title="Start time">
  							</td>
  							
  						</tr>
  						<tr>
  							<td colspan="2"> <input type="text" class="form-control" id="tsesdesc" name="tsesnm" placeholder="Description"></td>
  							
  							
  						</tr>
  						
  					</table>
  					<button id="btnaddSessionUsers" type="submit"  class="btn btn-primary" data-toggle="collapse" data-target="#addUsers">
					Save
					</button>
  			<!--		<div id="addUsers" class="collapse container">
  					<table class="table">
    						<thead>
      							<tr>
								<th></th>
        							<th>ID</th>
            							<th>Emp-ID</th>
								<th>Name</th>
								<th>DOB</th>
								<th>Joining Date</th>
								<th>College</th>
							</tr>
     
    						</thead>
    						<tbody>
							<tr>
								<td class="checkbox"><input type="checkbox" value=""> </td>
								<td>1</td>
            							<td>721</td>
								<td>Sumedha Raje</td>
								<td>18/10/1991</td>
								<td>22/12/2014</td>
								<td>Nowrosjee Wadia College</td>
      							</tr>
							<tr>
								<td class="checkbox"><input type="checkbox" name="chkbx_trainee" value=""></td>
								<td>2</td>
            							<td>321</td>
								<td>Abhijeet Majgaonkar</td>
								<td>18/06/1990</td>
								<td>22/12/2014</td>
								<td>IMCC College</td>
      							</tr>
      							
  						</tbody>
  					</table>
  					<input type="submit" value="Save Session" id="btnSaveSes" type="button"  class="btn btn-primary"></input>
  					<button id="btnCancelSes" type="button"  class="btn btn-primary">
  						Cancel
  					</button>
  					
  					</div>
  					</div>-->
  				
			</form>
			</div>
			<div id="divSes">
<table class="table table-hover">
<thead>
	<tr>
		<th>ID</th>
	        <th>Name</th>
	        <th>Trainer</th>
		<th>Date</th>
		<th>Time</th>
		<th>Status</th>
		<th>Technology</th>

      </tr>
</thead>
<tbody class="tbody">

	<?php
	
		$sess = new SessionDAOImpl();
		$tech = 
		$array_list = $sess->listSessions()->getArrayList();

		if(isset($array_list))
		{
			foreach($array_list as $sessn)
			{
	?>		
	<tr  class="success" id="rowselect" onclick ="window.open('session_handle.php?sess_id=<?php print $sessn->getId(); ?>','_self')">
	        <td><?php print $sessn->getId(); ?></td>
	        <td><?php print $sessn->getSessionName(); ?></td>
	        <td><?php print $sessn->getTrainer(); ?></td>
		<td><?php print date('Y-m-d', $sessn->getStartDateTime()); ?></td>
		<td><?php print date('H:m:s', $sessn->getStartDateTime()); ?></td>
		<td><?php print $sessn->getStatus(); ?></td>
		<td><?php print $techdao->getNameFromId($sessn->getTechId()); ?></td>
	</tr>
	<?php
			}
		}
		else
		{
			echo "!!!!!";
		}
	?>      
    </tbody>
  </table>
				
			</div>
			
		</div>
		
		</div>
		<div id="divf" class="divfooter" >
			<p> © 2007-2015 Spring Computing Technologies Pvt. Ltd., All Rights Reserved.</p>
		</div>
	</body>
	
</html>
